# -*- coding: utf-8 -*-

# __date:       2021/6/3
# __author:     YangChao
# __function:

import numpy as np
from decimal import Decimal


def qarange(start, end, step):
    if Decimal(str(end)) - Decimal(str(start)) < Decimal(str(step)) or step == 0:
        raise Exception('except not use qarange!')
    start_decimal = str(start)[::-1].find('.')
    step_decimal = str(step)[::-1].find('.')
    data_decimal = max([step_decimal, start_decimal])
    if data_decimal == -1:
        data_decimal = 0
    data_number = int((Decimal(str(end)) - Decimal(str(start))) / Decimal(str(step)))
    end_data = round(start + data_number * step, data_decimal)
    data_np = np.linspace(start, end_data, data_number + 1)
    data_list = [round(data, data_decimal) for data in data_np]
    res_list = [float(num) for num in data_list]
    return res_list
